package com.qianfeng.camerademo;

import java.io.File;

import com.qianfeng.camerademo.utils.FileUtils;

import android.support.v7.app.ActionBarActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;

/**
 * 
 * @ClassName: MainActivity
 * @说明:
 * @author 张唯
 * @date 2014-10-28 下午3:42:31
 */
public class MainActivity extends ActionBarActivity implements OnClickListener {
	private static final int REQUEST_CODE = 111;
	private Button photoBtn, photoBtn1, showBtn;
	private ImageView imageView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		imageView = (ImageView) findViewById(R.id.show_photo);
		photoBtn = (Button) this.findViewById(R.id.photo_btn);
		photoBtn1 = (Button) this.findViewById(R.id.photo_btn1);
		showBtn = (Button) this.findViewById(R.id.show_image);
		photoBtn.setOnClickListener(this);
		photoBtn1.setOnClickListener(this);
		showBtn.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.photo_btn:
			// 启动系统相机
			Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
			startActivityForResult(intent, REQUEST_CODE);
			break;
		case R.id.photo_btn1:
			try {
				
				File imageFile = FileUtils.getImageFile();
				if (null != imageFile) {
					Uri uri = Uri.fromFile(imageFile);
					
					// 启动系统相机
					Intent intent1 = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
					intent1.putExtra(MediaStore.EXTRA_OUTPUT, uri);
					startActivity(intent1);
				}
			} catch (Exception e) {
				e.printStackTrace();
			
			}
			break;
		case R.id.show_image:
			startActivity(new Intent(this, ShowImageActivity.class));
			break;
		}

	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
	}
}
